//
//  ModifyPasswordViewController.m
//  SaltLightDemo
//
//  Created by lzy on 2018/5/8.
//  Copyright © 2018年 lzy. All rights reserved.
//

#import "ModifyPasswordViewController.h"
#import "MGRequestService+My.h"
@interface ModifyPasswordViewController ()
@property (nonatomic , strong) UITextField *ysmmTF;
@property (nonatomic , strong) UITextField *xmmTF;
@property (nonatomic , strong) UITextField *cfmmTF;
@end

@implementation ModifyPasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"修改密码";
    [self initUI];
    // Do any additional setup after loading the view.
}
-(void)initUI{
    UIView * view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH, 165)];
    view1.backgroundColor = [UIColor add_colorWithRGBHexString:@"FFFFFF"];
    [self.view addSubview:view1];
    
    UIView * line1 = [[UIView alloc]initWithFrame:CGRectMake(0, 55, SCREEN_WIDTH, 1.0)];
    line1.backgroundColor = [UIColor add_colorWithRGBHexString:@"EFEFF4"];
    [view1 addSubview:line1];
    
    UIView * line2 = [[UIView alloc]initWithFrame:CGRectMake(0, 110, SCREEN_WIDTH, 1.0)];
    line2.backgroundColor = [UIColor add_colorWithRGBHexString:@"EFEFF4"];
    [view1 addSubview:line2];
    
//    1
    UILabel * label1 = [[UILabel alloc]initWithFrame:CGRectMake(25, 10, 100, 35)];
    label1.font = [UIFont boldSystemFontOfSize:14.0];
    label1.text = @"原始密码";
    label1.textColor = [UIColor add_colorWithRGBHexString:@"333333"];
    label1.textAlignment = NSTextAlignmentLeft;
    [view1 addSubview:label1];
    
    UITextField *ysmmTF = [[UITextField alloc] initWithFrame:CGRectMake(105, 17.5, self.view.frame.size.width-150, 20)];
    self.ysmmTF = ysmmTF;
    self.ysmmTF.font = [UIFont systemFontOfSize:14.0];
//    self.ysmmTF.keyboardType = UIKeyboardTypeNumberPad;
    self.ysmmTF.tag = 1;
    self.ysmmTF.secureTextEntry = YES;
    self.ysmmTF.textAlignment = NSTextAlignmentLeft;
    self.ysmmTF.returnKeyType = UIReturnKeyDone;
    self.ysmmTF.placeholder = @"点击输入原始密码";
    self.ysmmTF.font = [UIFont systemFontOfSize:14.0];
    [view1 addSubview:self.ysmmTF];

    
//    2
    UILabel * label2 = [[UILabel alloc]initWithFrame:CGRectMake(25, 10+55, 100, 35)];
    label2.font = [UIFont boldSystemFontOfSize:14.0];
    label2.text = @"新密码";
    label2.textColor = [UIColor add_colorWithRGBHexString:@"333333"];
    label2.textAlignment = NSTextAlignmentLeft;
    [view1 addSubview:label2];
    
    UITextField *xmmTF = [[UITextField alloc] initWithFrame:CGRectMake(105, 17.5+55, self.view.frame.size.width-150, 20)];
    self.xmmTF = xmmTF;
    self.xmmTF.font = [UIFont systemFontOfSize:14.0];
//    self.xmmTF.keyboardType = UIKeyboardTypeNumberPad;
    self.xmmTF.tag = 2;
    self.xmmTF.textAlignment = NSTextAlignmentLeft;
    self.xmmTF.returnKeyType = UIReturnKeyDone;
    self.xmmTF.placeholder = @"点击输入新密码";
    self.xmmTF.secureTextEntry = YES;
    self.xmmTF.font = [UIFont systemFontOfSize:14.0];
    [view1 addSubview:self.xmmTF];
    
//    3
    UILabel * label3 = [[UILabel alloc]initWithFrame:CGRectMake(25, 10+110, 100, 35)];
    label3.font = [UIFont boldSystemFontOfSize:14.0];
    label3.text = @"重复密码";
    label3.textColor = [UIColor add_colorWithRGBHexString:@"333333"];
    label3.textAlignment = NSTextAlignmentLeft;
    [view1 addSubview:label3];
    
    UITextField *cfmmTF = [[UITextField alloc] initWithFrame:CGRectMake(105, 17.5+110, self.view.frame.size.width-150, 20)];
    self.cfmmTF = cfmmTF;
    self.cfmmTF.font = [UIFont systemFontOfSize:14.0];
//    self.cfmmTF.keyboardType = UIKeyboardTypeNumberPad;
    self.cfmmTF.tag = 3;
    self.cfmmTF.textAlignment = NSTextAlignmentLeft;
    self.cfmmTF.returnKeyType = UIReturnKeyDone;
    self.cfmmTF.placeholder = @"再次输入新密码";
    self.cfmmTF.secureTextEntry = YES;
    self.cfmmTF.font = [UIFont systemFontOfSize:14.0];
    [view1 addSubview:self.cfmmTF];
    
    UIButton * button = [[UIButton alloc]initWithFrame:CGRectMake((SCREEN_WIDTH - 250)/2.0, CGRectGetMaxY(view1.frame)+60, 250, 40)];
    button.backgroundColor = [UIColor add_colorWithRGBHexString:@"FFD600"];
    [button setTitle:@"确定修改" forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:14.0];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
    button.layer.masksToBounds = YES;
    button.layer.cornerRadius = 20;
    [self.view addSubview:button];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
    
}
-(void)back:(UIButton * )btn{
    if ([self.xmmTF.text isEqualToString:self.cfmmTF.text]) {
        [MGRequestService requestModifyThePasswordWitholdPassword:self.ysmmTF.text AndnewPassword:self.cfmmTF.text success:^(MGBaseRspModel *model) {
            if (model.resultCode == 0) {
                [self showToastInViewController:@"修改成功"];
                [self.navigationController popViewControllerAnimated:YES];
            }else
            {
                [self showToastInViewController:model.errorMessage];
            }
        } failure:^(NSError *error) {
            [self showToastInViewController:@"修改失败"];
        }];
    }else
    {
        [self showToastInViewController:@"重复密码与新密码不一样"];
    }
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
